package binlogx

import (
	"fmt"
	"log"
	"regexp"
	"strings"
	"testing"
)

func TestParse(t *testing.T) {
	sql := `alter table cmdb.log
    add is_login bool default true;
`
	re := regexp.MustCompile(`(?i)(?:ALTER|CREATE|DROP|RENAME)\s+TABLE\s+(\S+)`)
	if m := re.FindStringSubmatch(sql); len(m) > 1 {
		name := strings.Trim(m[1], "`")
		log.Println(name)
		if strings.Contains(name, ".") {
			parts := strings.SplitN(name, ".", 2)
			name = parts[1]
		}
		fmt.Println(name)
	}
}
